<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------
namespace app\user_center\behavior\user\register_apple_before;

/**
 * 检测是否登陆过 未登录进行注册
 * @package app\user_center\behavior\user\register_apple_before
 * @author shiqiang
 */
class checkFirstLogic{
    public function run($params){
		$apple_id  	 = $params['apple_id'];
		$nick_name   = $params['nick_name'];
		$avatar_url  = $params['avatar_url'];
		
		$result = model('UcMemberApple', 'model\user') -> getDataByAppleid($apple_id);//检测是否注册
		if($result['code'] < 0){
			$result = model('Member', 'model\user') -> addUser($nick_name, 1, '暂无签名', $avatar_url, '2019-04-04');
			if($result['code'] > 0){
				$uid = $result['data'];
				$result = model('UcMemberApple', 'model\user') -> addData($uid, $apple_id);
				if($result['code'] < 0){
					return array_out(-1001, '苹果账户登陆失败');
				}
                // 注册发放优惠券
                auto_receive_coupon($uid, 0);
			}else{
				return array_out(-1001, '苹果账户登陆失败');
			}
		}
	}
}
 